package com.bigdata.management.utils;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import org.apache.ibatis.annotations.Mapper;

import java.util.function.Consumer;

public class CodeGen3531 {
        public static void main(String[] args) {
             //  String[] tables={ "governance_metric","governance_type","governance_assess_detail"};
            //  String[] tables={ "t_ds_task_definition","t_ds_task_instance"};
            //  String[] tables={ "governance_assess_table","governance_assess_tec_owner","governance_assess_global"};
            //  String[] tables={ "table_meta_info","table_meta_info_extra"  };

            String[] tables={ "table_meta_info"  };

            FastAutoGenerator.create("jdbc:mysql://127.0.0.1:3306/data_manage","root","123456")
                    .globalConfig(builder -> {
                        builder.author("chenxiaoyong")               //作者
                                .outputDir("D:\\BaiduNetdiskDownload\\data-management\\management\\src\\main\\java")    //输出路径(写到java目录)
                                .commentDate("yyyy-MM-dd")
                                .dateType(DateType.ONLY_DATE);  //选择实体类中的日期类型  ，Date or LocalDatetime
                    })
                    .packageConfig(builder -> {                 //各个package 名称
                        builder.parent("com.bigdata.management")
                                .moduleName("meta")
                                .entity("bean")
                                .service("service")
                                .serviceImpl("service.impl")
                                .controller("controller")
                                .mapper("mapper");

                    })
                    .strategyConfig(builder -> {
                        builder.addInclude(tables)
                                .serviceBuilder()
                                .formatServiceFileName("%sService")  //类后缀
                                .formatServiceImplFileName("%sServiceImpl")  //类后缀
                                .entityBuilder()
                                .enableLombok()  //允许使用lombok
                                .controllerBuilder()
                                .formatFileName("%sController")  //类后缀
                                .enableRestStyle()   //生成@RestController 否则是@Controller
                                .mapperBuilder()
                                //生成通用的resultMap 的xml映射
                                .enableBaseResultMap()  //生成xml映射
                                .superClass(BaseMapper.class)  //标配
                                .formatMapperFileName("%sMapper");

                    })

                    .templateConfig(new Consumer<TemplateConfig.Builder>() {
                        @Override
                        public void accept(TemplateConfig.Builder builder) {
                            // 实体类使用我们自定义模板
//                            builder.entity("templates/myentity.java");
                        }
                    })


                    .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                    .execute();
        }
  }
